package com.wangtao.firstapp.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.wangtao.firstapp.R;
import com.wangtao.firstapp.adapters.HomeVPAdapter;
import com.wangtao.firstapp.fragments.personfragments.ArticlesFragment;
import com.wangtao.firstapp.fragments.personfragments.SingleProductFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 个人界面下 点击 我的收藏 跳转到此页面
 * Created by lanouhn on 16/9/19.
 */
public class MyCollectionActivity extends AppCompatActivity {
    private ImageView iv_back_titlebar_mycollection;// 标题栏返回按钮
    private TabLayout tablayout_mycollection;//
    private ViewPager viewpager_mycollection;
    private HomeVPAdapter homeVPAdapter;// 复用此适配器

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mycollection);
        initView();
        initEvent();
        initData();
    }

    private void initView() {
        iv_back_titlebar_mycollection = (ImageView) findViewById(R.id.iv_back_titlebar_mycollection);// 标题栏返回按钮
        tablayout_mycollection = (TabLayout) findViewById(R.id.tablayout_mycollection);
        viewpager_mycollection = (ViewPager) findViewById(R.id.viewpager_mycollection);
    }

    private void initEvent() {
        // 标题栏返回按钮点击事件
        iv_back_titlebar_mycollection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initData() {
        ArrayList<String> tabnames = new ArrayList<>();
        tabnames.add("单品");
        tabnames.add("文章");
        ArrayList<Fragment> fragments = new ArrayList<>();
        SingleProductFragment singleProductFragment = new SingleProductFragment();
        fragments.add(singleProductFragment);
        ArticlesFragment articlesFragment = new ArticlesFragment();
        fragments.add(articlesFragment);
        homeVPAdapter = new HomeVPAdapter(getSupportFragmentManager(), tabnames, fragments);
        viewpager_mycollection.setAdapter(homeVPAdapter);
        tablayout_mycollection.setupWithViewPager(viewpager_mycollection);
    }

}
